//
//  MBService.h
//  Oldies Hits
//
//  Created by Diep Duong on 12/2/11.
//  Copyright (c) 2011 GNT Vietnam. All rights reserved.
//

#import <Foundation/Foundation.h>

#define TEST_API                            @"http://oldieshits.icj.jp/api/test2.php"
#ifdef  API_PRODUCTION    
    #define API_URL                         @"http://oldieshits.icj.jp"    
#else   
    #define API_URL                         @"http://oldieshits-test.icj.jp"    
#endif

#ifdef API_MOBION_COM
    #define API_MUSIC                       @"http://music.mobion.com" 
    #define API_MOBION                      @"http://api.mobion.com"
#else
    #define API_MUSIC                       @"http://musicapp.sgcharo.com"
    #define API_MOBION                      @"http://api.sgcharo.com:8080"
#endif

#define kHTTPHeader_Mobion_AppID            @"X-GNT-APPID"
#define kHTTPHeader_Mobion_OSVersion        @"X-GNT-OSVER"
#define kHTTPHeader_Mobion_DeviceID         @"X-GNT-DEVID"

@class MBService;
@class ASIFormDataRequest;
@class MemberStatusResponse;
@class SongResponse;
@class GetConfigResponse;
@class MBLastNotificationResponse;
extern NSString *MBErrorDomain;
static NSError *mb_err(int code)
{
    return [NSError errorWithDomain:MBErrorDomain code:code userInfo:nil];
}

typedef enum 
{
    ActionTypeNone  = 0,
    ActionTypeGetUserPoint,
//    ActionTypeGetTop100,  
} ActionType;

typedef enum 
{
    StatusCodeSuccess                   = 0,
    StatusCodeFailed                    = 1,
    StatusCodeNetworkUnavailable        = 90,
    StatusCodeUnknown                   = 100
} StatusCode;

typedef enum 
{
    SearchSongByCategoryId  = 0,
    SearchSongByArtistId,
    SearchSongBySongName
    
} SearchSongType;

@protocol MBServiceDelegate

// COMMON ERROR (server down and/or network unavailable)
- (void)mbService:(MBService *)service didFailWithError:(NSError *)error;
- (void)mbServiceGetListSongRandomSucceed:(MBService *)service responses:(NSMutableArray*)response;
- (void)mbServiceGetListSongRandomFailed:(MBService *)service;
@end

@interface MBService : NSObject 
{
    id                 _delegate;
    BOOL               _connecting;
    NSURLConnection   *_connection;
    NSMutableData     *_buffer;  
    ActionType         _action;
    BOOL               _canShowAlert;
    BOOL               _canShowLoading;
    int                _timeout;
    NSTimer           *_timer;
    
    ASIFormDataRequest      *_asiRequest;
    BOOL               mobionService; 
}

@property (nonatomic, assign) id delegate;
@property (nonatomic, assign) BOOL connecting;
@property (nonatomic, retain) NSURLConnection *connection;
@property (nonatomic, retain) NSMutableData *buffer;

@property (nonatomic, assign) ActionType action;
@property (nonatomic, assign) BOOL canShowAlert;
@property (nonatomic, assign) BOOL canShowLoading;
@property (nonatomic, assign) int timeout;

- (void)getUserPoint;
//- (void)getTermOfUse;
//- (void)getPrivacyPolicy;
//- (void)getDirectLink;
//- (void)getTop100;

@end
